package com.zj.z11select.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Swagger 配置类
 * @author ZHOUJIE <a>z-houjie@qq.com</a>
 * @date 2021-07-06 14:01
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 配置了Swagger的Docket的bean实例
     * @return Docket
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("ZHOUJIE")
                .apiInfo(apiInfo())
                /** 是否启用swagger默认启动*/
                .enable(true)
                .select()
                /**
                 *  RequestHandlerSelectors      配置要扫描的接口方式
                 *  basePackage()                指定要扫描的包
                 *  withClassAnnotation         扫描类上的注解，参数是一个注解的反射对象
                 *  withMethodAnnotation        扫描方法上的注解
                 */
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                /**
                 * 过滤什么路径
                 *  any()          扫描全部
                 *  none()         不扫描
                 *  ant()          只扫描
                 */
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置swagger 信息apiinfo
     * @return ApiInfo
     */
    private ApiInfo apiInfo(){

        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder
                .title("《Z11 Select》商城的SwaggerAPI文档")
                .description("青山不改绿色长流,你我山巅自相逢")
                .version("v2.0.1")
                .termsOfServiceUrl("https://blog.csdn.net/weixin_43206491")
                //作者信息
                .contact(new Contact("ZHOUJIE","https://blog.csdn.net/weixin_43206491","z-houjie@qq.com"))
                .license("Apache 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
                .extensions(new ArrayList<>());
        return apiInfoBuilder.build();
    }
}
